package com.kronos.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.kronos.audio.MusicStream;
import com.kronos.audio.SoundStream;
import com.kronos.gui.Canvas;
import com.kronos.listeners.WindowListener;
import com.kronos.managers.AssetManager;
import com.kronos.managers.GameStateManager;

public class KronosGame extends ApplicationAdapter {
	public static final String TITLE = "Kronos2D";

	public static int SCALE = 3;

	public static int V_WIDTH = 320 * SCALE;
	public static int V_HEIGHT = 240 * SCALE;

	private SpriteBatch sb;
	private OrthographicCamera cam, hudCam;

	private GameStateManager gsm;
	private Canvas canvas;

	private InputMultiplexer imp;
	
	public static AssetManager manager;
	
	private Pixmap pm;
	
	@Override
	public void create() {
		V_WIDTH = Gdx.graphics.getWidth();
		V_HEIGHT = Gdx.graphics.getHeight();
		
		sb = new SpriteBatch(1000);

		cam = new OrthographicCamera();
		cam.setToOrtho(false, V_WIDTH, V_HEIGHT);
		
		hudCam = new OrthographicCamera();
		hudCam.setToOrtho(false, V_WIDTH, V_HEIGHT);
		
		manager = new AssetManager();
		manager.loadTexture("introscreen.jpg");
		manager.loadTexture("container.png");
		manager.loadTexture("gui.png");
		manager.loadTexture("terrain.png");
		manager.loadTexture("mountains.png");
		manager.loadTexture("parallax.png");
		manager.loadTexture("clouds.png"); 
		manager.loadTexture("player.png");
		manager.loadTexture("gun.png");
		manager.loadTexture("waterblend.png");
		
		MusicStream.loadMusic("intro.mp3", "intro");
		MusicStream.loadMusic("Soliloquy.mp3", "game");
		
		SoundStream.loadSound("hover.mp3", 1);
		SoundStream.loadSound("click.mp3", 2);
		SoundStream.loadSound("bounce.mp3", 3);
		
		imp = new InputMultiplexer();
		imp.addProcessor(new WindowListener());

		pm = new Pixmap(Gdx.files.internal("cursor.png"));
        Gdx.input.setCursorImage(pm, 0, 0);
        
		canvas = new Canvas(this);
		
		gsm = new GameStateManager(this);
		
		Gdx.input.setInputProcessor(imp);
	}
	
	@Override
	public void render() {
		gsm.update();
		gsm.render();
	}

	public SpriteBatch getSpriteBatch() {
		return sb;
	}

	public OrthographicCamera getCamera() {
		return cam;
	}
	
	public OrthographicCamera getHudCamera() {
		return hudCam;
	}

	public Canvas getCanvas() {
		return canvas;
	}

	public void addInputMultiplexer(InputProcessor processor) {
		imp.addProcessor(processor);
	}
	
	public void removeInputMultiplexer(InputProcessor processor) {
		imp.removeProcessor(processor);
	}

	public void dispose() {
		gsm.dispose();
		pm.dispose();
	}

	public void resize(int w, int h) {
		cam.setToOrtho(false, V_WIDTH, V_HEIGHT);
	}

	public void pause() {
	}

	public void resume() {
	}
}
